mui.init({
	beforeback:function() {
		var parentObj = plus.webview.currentWebview().opener();
		mui.fire(parentObj, 'dataList');
	},
    pullRefresh: {
        container: "#refreshContainer", //下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
        down: {
            style: 'circle', //必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
            color: '#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
            height: '50px', //可选,默认50px.下拉刷新控件的高度,
            range: '100px', //可选 默认100px,控件可下拉拖拽的范围
            offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
            auto: false, //可选,默认false.首次加载自动上拉刷新一次
            callback: function () {
                ebook_details.getEbookDetail();
                setTimeout(function () {
                    mui('#refreshContainer').pullRefresh().endPulldownToRefresh(flag);
                }, 1000)
            }
        }
    }
});
var ebook_details;
var ebookid;
var flag = false;
mui.plusReady(function () {
	hideScrollBar();
    var self = plus.webview.currentWebview();
    ebookid = self.bookid;
    ebook_details = new Vue({
        el: '#book_detail',
        data: {
            details: '',
            collection_status: 'NO',
            pay_type: 'wx_pay',
            payway: 'wxpay',
        },
        computed: {
            styleObject: function () {
                if (this.collection_status == 'YES') {
                    var color = {
                        color: '#FEBB23'
                    };
                    return color;
                } else {
                    var color = {
                        color: '#8f8f94'
                    };
                    return color;
                }
            },
        },
        mounted() {
            this.getEbookDetail();
        },
        methods: {
            getEbookDetail: function () {
                var api_host = plus.storage.getItem('HOST_URL');
                mui.ajax({
                    url: api_host + '/api/ebook/index/getdetail',
                    dataType: 'json',
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    data: {
                        'bookid': ebookid,
                    },
                    type: 'get',
                    success: function (msg) {
                        if (msg.code == 1) {
                            ebook_details.details = msg.data;
                            ebook_details.collection_status = msg.data.collection_status;
                        } else {
                            mui.toast(msg.msg, {duration: '200',type: 'div'});
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('请求出错，请重试', {duration: '200',type: 'div'});
                    },
                    complete:function (XMLHttpRequest,status) {
                        plus.nativeUI.closeWaiting();
                    }
                });
            },
            open_book_mulu: function (bookid, buy_status) {
                mui.openWindow({
                    url: 'catalogTab.html',
                    extras: {
                        'bookid': bookid,
                        'buy_status': buy_status,
                        'bookTitle':this.details.title
                    },
                    createNew:false,
                    show: {
                        autoShow: true,
                        aniShow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                    }
                })
            },
            open_shidu: function (bookid) {
                mui.openWindow({
                    url: 'tryRead.html',
                    id:'tryRead.html',
                    extras: {
                        'bookid': bookid
                    },
                    createNew: false,
                    show: {
                        autoShow: true,
                        aniShow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                    }
                })
            },
            open_read: function (bookid,buy_status) {
                mui.openWindow({
                    url: 'read.html',
                    extras: {
                        'bookid': bookid,
                        'sid':'',
                        'buyStatus':buy_status
                    },
                    createNew:false,
                    show: {
                        autoShow: true,
                        aniShow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                    }
                })
            },
            open_price_box: function () {
                var api_host = plus.storage.getItem('HOST_URL');
                var self = this;
                mui.ajax({
                    url: api_host + '/api/linxuan/user/checkLoginStatus',
                    dataType: 'json',
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    type: 'get',
                    success: function (msg) {
                        if (msg.code == 1) {
                            if(msg.data.vip > 1){
                                mui.toast('您可以享受VIP价格', {duration: '1000',type: 'div'});
                            }
                            $('.popMask').show();
                            $('.popPay').animate({
                                'bottom': '0%'
                            }, 300).show();
                        } else {
                            mui.toast('您还没有登录哦', {duration: '300',type: 'div'});
                            setTimeout(function() {
							mui.openWindow({
								url: '../../logReg/login.html',
								createNew: false,
								id: 'loginHtml',
								show: {
									autoShow: true,
									anishow: 'pop-in',
									duration: 400
								},
								waiting: {
									autoShow: false,
								}
							});
						}, 1000)
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('登录状态请求失败请重试', {duration: '300',type: 'div'});
                    }
                });

            },
            get_shoucang: function () {
                var collection_info = {
                    'title': this.details.title,
                    'thumb': this.details.thumb,
                    'views': this.details.views,
                    'oneWords': this.details.oneWords,
                    'price': this.details.novipprice,
                    'id': this.details.id,
                };
                updateProductCollection('ebook',this.details.id, this.details.title,collection_info,ebook_details);
            },
            pay_way: function (type) {
                this.payway = type;
            },
            close_pay_box: function () {
                $('.popMask').hide();
                $('.popPay').animate({
                    'bottom': '-100%'
                }, 300).hide(300);
            },
            open_zhifu: function () {
                var goodsInfo = {
                    'id': this.details.id,
                };
                new pay().start('ebook',this.payway,1,goodsInfo);
            },
            openKefu:function () {
                customerService();
            },
            /*ebookShare:function () {
                var self = this;
                // plus.share.getServices(successCB, errorCB);
                var ebookMessage = {
                    'type':'miniProgram',
                    'title': self.details.title, //分享卡片显示的标题
                    'content': self.details.description,  //分享出去卡片显示的描述信息
                    'thumbs': [self.details.thumb], //分享缩略图
                    'miniProgram':{
                        'id':'gh_f4a316c693e0',
                        'path':'/pages/details/details?id='+self.details.id,
                        "webUrl": "https://shop383116049.taobao.com/",
                        'type':0,
                    },
                }
                //调起分享
                plusShare(ebookMessage, function (res) {
                    //分享回调函数
                    if (res) {
                        plus.nativeUI.toast("分享成功");
                    } else {
                        plus.nativeUI.toast("分享失败");
                    }
                })
            }*/
        },
    })
})

window.addEventListener('dataList',function(event){
    ebook_details.getEbookDetail();
});


